package com.xiaoxin.lease.web.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoxin.lease.model.entity.LeaseTerm;
import com.xiaoxin.lease.model.entity.RoomLeaseTerm;
import com.xiaoxin.lease.web.admin.mapper.LeaseTermMapper;
import com.xiaoxin.lease.web.admin.service.LeaseTermService;
import com.xiaoxin.lease.web.admin.service.RoomLeaseTermService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author liubo
* @description 针对表【lease_term(租期)】的数据库操作Service实现
* @createDate 2023-07-24 15:48:00
*/
@Service
public class LeaseTermServiceImpl extends ServiceImpl<LeaseTermMapper, LeaseTerm>
    implements LeaseTermService{

    @Autowired
    RoomLeaseTermService roomLeaseTermService;

    @Override
    public List<LeaseTerm> getLeaseTerm(Long id) {
        List<LeaseTerm> leaseTermList = new ArrayList<>();
       List<RoomLeaseTerm> roomLeaseTermList =  roomLeaseTermService.list(new LambdaQueryWrapper<RoomLeaseTerm>().eq(RoomLeaseTerm::getRoomId,id));
       if(roomLeaseTermList.size()>0){
           leaseTermList = super.list(new LambdaQueryWrapper<LeaseTerm>().in(LeaseTerm::getId,roomLeaseTermList.stream().map(f -> f.getLeaseTermId()).toList()));
       }
        return leaseTermList;
    }
}




